<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'科室列表'),
	//array('op'=>'edit','title'=>'添加科室'),	
);
if($_RQ['op']=='list'){
	$params=array('area_id'=>$this->area_id);
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','title','groupid','area_id','storeid','workerid','status','image','storetype','price');
	$list=pdo_getslice('jy_zhongyi_lesson',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
				$item['worker']=pdo_get('jy_zhongyi_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['workerid']));
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'tip'=>'报名科室','list'=>array(
			array('name'=>'title','title'=>'科室名称','type'=>'string'),
			array('name'=>'image','title'=>'科室图片','type'=>'image'),
			array('name'=>'area_id','title'=>'所属区域','type'=>'select','options'=>'areas'),
			array('name'=>'storeid','title'=>'所属校区','type'=>'select','options'=>'stores'),
			array('name'=>'groupid','title'=>'科室类型','type'=>'select','options'=>'groups'),
		//	array('name'=>'worker.name','title'=>'老师','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'switch','set'=>'set'),
		),'action'=>array(
			array('title'=>'查看详情','type'=>'href','op'=>'look'),
		)),
		'search'=>array(
			array('name'=>'area_id','width'=>10,'title'=>'所属区域','type'=>'select','options'=>'areas'),
			array('name'=>'storeid','width'=>10,'title'=>'所属校区','type'=>'select','options'=>'stores'),
			array('name'=>'groupid','width'=>10,'title'=>'科室类型','type'=>'select','options'=>'groups'),
			array('name'=>'workerid','width'=>10,'title'=>'讲师','type'=>'select','options'=>'workers','option_title'=>'name'),
			array('name'=>'title','width'=>10,'title'=>'科室名称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	$return['stores']=pdo_getall('jy_zhongyi_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['areas']=pdo_getall('jy_zhongyi_area',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['groups']=pdo_getall('jy_zhongyi_lesson_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	exi($return);
}
if($_RQ['op']=='look'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_zhongyi_lesson',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['starttime']=date('Y-m-d',$item['starttime']);
		$item['endtime']=date('Y-m-d',$item['endtime']);
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'look',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回科室列表'),
		),
		'look'=>array(
					array('name'=>'title','title'=>'科室名称','type'=>'string'),
					array('name'=>'storeid','title'=>'所属校区','type'=>'select','options'=>'stores'),
					array('name'=>'area_id','title'=>'所属区域','type'=>'select','options'=>'areas'),
					array('name'=>'groupid','title'=>'科室类型','type'=>'select','options'=>'groups'),
					array('name'=>'storetype','title'=>'分校类型','type'=>'radio','options'=>'storetype'),
					array('name'=>'starttime','title'=>'选课开启时间','type'=>'string'),
					array('name'=>'endtime','title'=>'选课结束时间','type'=>'string'),
					array('name'=>'logo','title'=>'logo','type'=>'image','help'=>'建议尺寸：640宽*220高'),
					array('name'=>'image','title'=>'展示图片','type'=>'image','help'=>'建议尺寸：640宽*220高'),
					array('name'=>'description','title'=>'简要描述','type'=>'text'),
					array('name'=>'content','title'=>'详细介绍','type'=>'richtext'),
					array('name'=>'paixu','title'=>'排序','type'=>'string'),
					array('name'=>'status','title'=>'状态','type'=>'switch'),
		)
	);
	$return['storetype']=$this->storetype;
	$return['htmls']=$htmls;
	$return['areas']=pdo_getall('jy_zhongyi_area',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['stores']=pdo_getall('jy_zhongyi_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['groups']=pdo_getall('jy_zhongyi_lesson_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	exi($return);
}